<!DOCTYPE html>
<html>
	{include file="public1/_header" /}
	<!-- 配置文件 -->
	<script type="text/javascript" src="__STATIC__/static/ueditor/ueditor.config.js"></script>
	<!-- 编辑器源码文件 -->
	<script type="text/javascript" src="__STATIC__/static/ueditor/ueditor.all.js"></script>
	<body style="background: #fff;">
		<div>
			<div class="layui-row">
				<div class="layui-col-md12">
					<form class="layui-form" action="">
						<div class="layui-card">
							<div class="layui-card-body">

								<div class="layui-col-md8">
									<table class="layui-table table-form">
										<colgroup>
											<col width="100">
											<col>
										</colgroup>
										<tbody>
											<tr>
												<th>标题 <span style='color:red'>*</span></th>
												<td>
													<input lay-reqText="标题必须填写" type="text" name="title" required lay-verify="required" autocomplete="off"
													 class="layui-input title">
												</td>
											</tr>
											<tr>
												<th>置顶</th>
												<td>
													<input type="checkbox" id="istop" name="istop" lay-filter="switchTest" lay-skin="switch" lay-text="是|否">
												</td>
											</tr>
										</tbody>
									</table>
								</div>
								<div class="layui-col-md4">
									<table class="layui-table table-form">
										<colgroup>
											<col width="100">
											<col>
										</colgroup>
										<tbody>
											<?php
												$data = [
													'cname'=>'缩略图',
													'ename'=>'image',
													'descript'=>'缩略图',
													'validate'=>0,
													'value'=>"",
												];
												thumb_temp($data,[]);
											?>
											<tr>
												<th>显示</th>
												<td>
													<input type="checkbox" id="show" name="show" lay-filter="switchTest" lay-skin="switch" lay-text="是|否"
													 checked>
												</td>
											</tr>
											
										</tbody>
									</table>
								</div>
								<div class="layui-col-md12" style="padding-bottom: 65px;">
									<table class="layui-table table-form">
										<colgroup>
											<col width="100">
											<col>
										</colgroup>
										<tbody>
											<?php
												$data = [
													'cname'=>'图集',
													'ename'=>'images',
													'descript'=>'图集',
													'validate'=>1,
													'value'=>"",
												];
												thumbs_temp($data,[]);
											?>
											
											<tr>
												<th>摘要<span style='color:red'>*</span></th>
												<td>
													<textarea id="description" name="description" class="layui-textarea" lay-verify="required"></textarea>
												</td>
											</tr>
											<tr>
												<th>发布群体 <span style='color:red'>*</span></th>
												<td>
													<ul id="demoTree" class="dtree" data-id="0"></ul>
												</td>
											</tr>

											<tr>
												<th>排序</th>
												<td>
													<input type="number" value="100" name="sort" required lay-verify="required" autocomplete="off" class="layui-input">
												</td>
											</tr>
										</tbody>
									</table>
								</div>

								<div style="text-align: center;" class="layui-layout-admin">
									<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
									<button type="button" id="close"  class="layui-btn layui-btn-primary">放弃</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		$(function() {
			layui.extend({
				dtree: 'dtree/dtree'
			}).use(['form', 'upload', 'dtree', 'laydate', 'tree', 'util'], function() {
				var form = layui.form;
				var $ = layui.jquery;
				var laydate = layui.laydate;
				var tree = layui.tree;
				var util = layui.util;
				var dtree = layui.dtree;
				form.verify({
					varVerify: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!new RegExp("^[a-zA-Z]([-_a-zA-Z0-9]{3,20})$").test(value)) {
							return '必须以字母开头的3-20位英文字符串';
						}
					}
				});

				laydate.render({
					elem: '#start_time',
					type: 'datetime',
					format: 'yyyy-MM-dd HH:mm:ss'
				});
				laydate.render({
					elem: '#end_time',
					type: 'datetime',
					format: 'yyyy-MM-dd HH:mm:ss'
				});
				
				// 初始化树
				var DemoTree = dtree.render({
					elem: "#demoTree",
					data: {$egetClass},
					menubar: true,
					checkbar: true,
					checkbarType: "all"
				});
				
				dtree.on("node(demoTree)", function(obj) {
					var nodeId = obj.param.nodeId;
				
					DemoTree.clickNodeCheckbar(nodeId); // 点击节点选中复选框
				
					var checkbarNodes = dtree.getCheckbarNodesParam("demoTree");
				});
				
				$("#close").click(function(){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				})
				
				//监听提交
				form.on('submit(formDemo)', function(obj) {
					if (obj.field.show) {
						obj.field.show = 1
					} else {
						obj.field.show = 0
					}
					if (obj.field.istop) {
						obj.field.istop = 1
					} else {
						obj.field.istop = 0
					}
					var index = parent.layer.getFrameIndex(window.name);
					var lfc = top.layerFrameConfig;
					var info = lfc.iframeB.info;

					var param = dtree.getCheckbarNodesParam(DemoTree);
					var ids = [];
					param.forEach(function(item, index) {
						if(item.basicData){
							ids.push(item.basicData)
						}
					})
					obj.field.class_ids = ids;
					obj.field.type = 1;
					$.post("{:url('add')}", obj.field, function(res) {
						if (res.status == 1) {
							layer.msg('添加成功', {
								icon: 1,
								time: 300
							}, function() {
								parent.layer.close(index); //再执行关闭
								info.reload()
							});

						} else {
							layer.msg(res.message)
						}
					})
					return false;
				});



			});


		})
	</script>
</html>
